package it.cst.entity.dao;

import it.cst.entity.Role;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class RoleDAOImpl implements RoleDAO{
	@Autowired
	private SessionFactory sessionFactory;
	
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	@Override
	public void addRole(Role role) {
		// TODO Auto-generated method stub
		
	}

	@SuppressWarnings("unchecked")
	public List<Role> listRole() {
		return sessionFactory.getCurrentSession().createQuery("from Role").list();
	}

	@Override
	public void removeRole(Integer id) {
		// TODO Auto-generated method stub
		
	}

	@SuppressWarnings("unchecked")
	public Role getRole(String roleName) {
		List<Role> roleList = sessionFactory.getCurrentSession().createQuery("from Role").list();
		for(Role role : roleList)
		{
		  if(role.getRole().equalsIgnoreCase(roleName))
			  return role;
		}
		return null;
	}

}
